package com.googlecode.connectlet.crypto.stream;

import java.io.InputStream;

import com.googlecode.connectlet.crypto.cipher.Encipheror;

public class CfbEncipheror extends FeedbackCipher {
	private static final long serialVersionUID = 1L;

	public CfbEncipheror(Encipheror cipher, byte[] iv) {
		super(cipher, iv);
	}

	@Deprecated
	@Override
	public int output() {
		throw new UnsupportedOperationException();
	}

	@Deprecated
	@Override
	public void output(byte[] b, int off, int len) {
		throw new UnsupportedOperationException();
	}

	@Override
	public int update(int b) {
		block[blockOffset] ^= b;
		int result = block[blockOffset];
		blockOffset ++;
		if (blockOffset == blockSize) {
			blockOffset = 0;
			cipher.encrypt(block, 0, block, 0);
		}
		return result;
	}

	@Deprecated
	@Override
	public InputStream decrypt(final InputStream in) {
		throw new UnsupportedOperationException();
	}
}